﻿
' ***********************************************************************
' Assembly         : Ioc
' Author           : Tim Ford
' Created          : 10-04-2013
'
' Last Modified By : Tim Ford
' Last Modified On : 10-04-2013
' ***********************************************************************
' <copyright file="SetValueOf.vb" company="Tim Ford">
'     Copyright (c) Tim Ford. All rights reserved.
' </copyright>
' <summary></summary>
' ***********************************************************************
''' <summary>
''' Class SetValueOf.
''' </summary>
Public Module SetValueOf
    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As String, ByVal value As Object)
        If String.IsNullOrWhiteSpace(item) Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), value.ToString, "")
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Boolean, ByVal value As Object)
        If item = Nothing Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CBool(value), False)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Boolean?, ByVal value As Object)
        If item Is Nothing OrElse Not item.HasValue Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CBool(value), Nothing)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Short, ByVal value As Object)
        If item = Nothing Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CShort(value), CShort(0))
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Short?, ByVal value As Object)
        If item Is Nothing OrElse Not item.HasValue Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CShort(value), Nothing)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Integer, ByVal value As Object)
        If item = Nothing Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CInt(value), 0)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Integer?, ByVal value As Object)
        If item Is Nothing OrElse Not item.HasValue Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CInt(value), Nothing)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Long, ByVal value As Object)
        If item = Nothing Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CLng(value), 0)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Long?, ByVal value As Object)
        If item Is Nothing OrElse Not item.HasValue Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CLng(value), Nothing)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Double, ByVal value As Object)
        If item = Nothing Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CDbl(value), 0)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Double?, ByVal value As Object)
        If item Is Nothing OrElse Not item.HasValue Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CDbl(value), Nothing)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Decimal, ByVal value As Object)
        If item = Nothing Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CDec(value), 0)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Decimal?, ByVal value As Object)
        If item Is Nothing OrElse Not item.HasValue Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CDec(value), Nothing)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Single, ByVal value As Object)
        If item = Nothing Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CSng(value), 0)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Single?, ByVal value As Object)
        If item Is Nothing OrElse Not item.HasValue Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CSng(value), 0)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Date, ByVal value As Object)
        If item = Nothing Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CDate(value), Date.MinValue)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension()>
    Public Sub SetValue(ByRef item As Date?, ByVal value As Object)
        If item Is Nothing OrElse Not item.HasValue Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CDate(value), Nothing)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension(), CLSCompliant(False)>
    Public Sub SetValue(ByRef item As UShort, ByVal value As Object)
        If item = Nothing Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CUShort(value), CUShort(0))
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension(), CLSCompliant(False)>
    Public Sub SetValue(ByRef item As UShort?, ByVal value As Object)
        If item Is Nothing OrElse Not item.HasValue Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CUShort(value), Nothing)
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension(), CLSCompliant(False)>
    Public Sub SetValue(ByRef item As UInteger, ByVal value As Object)
        If item = Nothing Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CUInt(value), CUInt(0))
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension(), CLSCompliant(False)>
    Public Sub SetValue(ByRef item As UInteger?, ByVal value As Object)
        If item Is Nothing OrElse Not item.HasValue Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CUInt(value), Nothing)
    End Sub
    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension(), CLSCompliant(False)>
    Public Sub SetValue(ByRef item As ULong, ByVal value As Object)
        If item = Nothing Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CULng(value), CULng(0))
    End Sub

    ''' <summary>
    ''' Sets the value.
    ''' </summary>
    ''' <param name="item">The item.</param>
    ''' <param name="value">The value.</param>
    <System.Runtime.CompilerServices.Extension(), CLSCompliant(False)>
    Public Sub SetValue(ByRef item As ULong?, ByVal value As Object)
        If item Is Nothing OrElse Not item.HasValue Then
            Return
        End If
        item = If(Not DBNull.Value.Equals(value), CULng(value), Nothing)
    End Sub


End Module

